
import SwiftUI
import GRDB

struct DuetContactsView: View {
    @State var rows = [Row]()

    var body: some View {
        List {
            ForEach(rows) { row in
                NavigationLink(
                    destination: DuetContactView(row: row),
                    label: {
                        HStack {
                            Text(row["ZDISPLAYNAME"] ?? "")
                            let ids: [String?] = [row["ZIDENTIFIER"], row["ZCUSTOMIDENTIFIER"]]
                            Spacer()
                            Text(ids.compactMap {$0}.joined(separator: " | "))
                        }
                    })
            }
        }
    }
}

struct DuetContactsView_Previews: PreviewProvider {
    static var previews: some View {
        DuetContactsView()
    }
}

extension Row: Identifiable {
    public var id: Int {
        return self["Z_PK"] ?? self["ROWID"]
    }
}
